package com.tom.architect.day17.simple5;

public class Client {
    // 深拷贝
    public static void main(String[] args) {
        User user = new User();
        user.age = 23;
        user.userName = "Tom";
        user.userAddress = new Address("福南", "长沙");

        // 深拷贝: 里面的对象，也克隆了。
        try {
            User copyUser = user.clone(); // 拷贝对象
//            System.out.println("name:" + user.userName + " addr:" + user.userAddress.addressName);
//            System.out.println("name:" + copyUser.userName + " addr:" + copyUser.userAddress.addressName);
            copyUser.userAddress.addressName = "深圳珠海";
            copyUser.userName = "XiaoLi";
            System.out.println("name:" + user.userName + " addr:" + user.userAddress.addressName);
            System.out.println("name:" + copyUser.userName + " addr:" + copyUser.userAddress.addressName);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println("-----------------");

    }
}
